$(document).ready(function() {
    // Carousel on homepage
    $('#homePhotoCollection').loopedSlider();


    $("a#signin").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });

    $("a#search").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });

    $("a#searchResultsLink").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500,
        'scrolling': 'auto'
    });

    $("#contactLink").fancybox({
        'zoomOpacity': true,
        'overlayShow': true,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500
    });
});


function ShowMore(container, morelink, lesslink)
{
    if ($("#" + container).is(":visible"))
    {
        $("#" + container).hide("slow", function() { $("#" + morelink).show(); });
    }
    else
    {
        $("#" + morelink).hide();
        $("#" + container).show("slow");
    }
}

function ShowCaption(container, which)
{

    if(which == "hide")
    {
        $("#" + container).hide("slow");
    }
    else
    {
        $("#" + container).show("slow");
    }
}

function Login()
{
    $("#errorMessage").html();
    var qsKey = "ReturnUrl";
    var redirectUrl = "";
    var qsIndex = location.search.indexOf(qsKey);
    if (qsIndex > 0)
        redirectUrl = unescape(location.search.substring(qsIndex + qsKey.length + 1));
        
    var username = $("#txtUserName").val();
    var password = $("#txtPassword").val();

    $.ajax({
        url: "/Account.aspx/Login",
        data: ({ username: username, password: password }),
        success: function(data)
        {
            if (data != "success")
                $("#errorMessage").html(data);
            else
            {
                $("#siginSection").hide();
                $.fancybox.close();
                if (redirectUrl != "")
                    window.location = redirectUrl;
            }
        }
    });

}

function Logoff()
{

    $.ajax({
        url: "/Account.aspx/Logoff",
        success: function(data)
        {
            alert("your logged off");
        }
    });

}

function Search()
{

    var searchTerm = $("#searchTextbox").val();

    $.ajax({
        url: "/Home.aspx/Search",
        data: ({ searchTerm: searchTerm }),
        success: function(data)
        {

            $("#searchResultsContainer").html(data);
            $("#searchResultsLink").trigger("click");
            
        }
    });

}